package com.ZengQi.event.dao.impl;

import com.ZengQi.event.dao.PublisherDao;
import com.ZengQi.event.entity.Publisher;
import com.ZengQi.event.util.SearchUtils;
import com.ZengQi.event.util.UpdateUtils;

import java.util.List;

public class PublisherDaoImpl implements PublisherDao {
    @Override
    public Publisher getPublisher(Publisher conditionPublisher) {
        String sql="select publisher_id publisherId,login_pnum loginPnum,login_pwd loginPwd,publisher_name publisherName,pubisher_topic publisherTopic from publisher where login_pnum=?";
        List<Publisher> publishers = SearchUtils.searchForList(Publisher.class, sql, conditionPublisher.getLoginPnum());
        if(publishers.size()!=0){
            return publishers.get(0);
        }else{
            return null;
        }

    }

    @Override
    public boolean deletePublisher(Publisher conditionPublisher) {
        String sql="delete from publisher where publisher_name=?";
        boolean update = UpdateUtils.update(sql, conditionPublisher.getPublisherName());

        return update;
    }

    @Override
    public boolean insertPublisher(Publisher publisher) {
        String sql="insert into publisher values(null,?,?,?,?)";
        boolean update = UpdateUtils.update(sql, publisher.getLoginPnum(), publisher.getLoginPwd(), publisher.getPublisherName(), publisher.getPublisherTopic());


        return update;
    }
}
